' CheckIn / CheckOut Terminal
' ------------------------------------------------------------------
' Copyright (C) 2012 TEAM
' ------------------------------------------------------------------

' Implementation for a CheckIn / CheckOut Terminal.

Option Explicit
Option Base Explicit

#Include ../PassengerCard/PassengerCard.DEF ' Declarations common to BasicCard and Terminal programs

#Include ../Includes/BasicCardUtilities.DEF
#Include ../Includes/BasicCardCommErrors.DEF
#Include ../Includes/BasicCardColours.DEF
#Include ../Includes/CommonTypes.DEF
#Include ../Includes/CommonFunctions.DEF
#Include ../Includes/CommonTerminalFunctions.DEF

#Include Misc.DEF

Call WaitForCard()
ResetCard : Call CheckSW1SW2()

' Check that the application name is correct
Private Name$ : Call GetApplicationID (Name$) : Call CheckSW1SW2()
If Name$ <> ApplicationName$ Then Print "This is not a ShipControl Card!" : Exit


' Get the card data to check if its personalised.
Private cardData as Travel : Call GetCardData(cardData) : Call CheckSW1SW2()
' If the card is not personalied, exit.
If SW1SW2 = swNotPersonalised Then
   Print "Karte nicht personalisiert!" 
   Exit
End If


Private status As Byte

Print "---------------------------------------------------"
Print "Welcome to ShipControl Checkin / Checkout Terminal."
Print "---------------------------------------------------"

Private now As DateTime
Call GetDateTime(now)
Private today as Date
today.Day = now.Day
today.Month = now.Month
today.Year = now.Year


If (IsInDuration(cardData.TravelStartDate, cardData.TravelEndDate, today) = 0) Then
   Print "Passenger boarding status: " 
   If cardData.TravelPassengerOnBoard = 1 Then
      Print "Currently on-Board, will be checked out."
   Else
      Print "Currently off-Board, will be checked in."
   End If
   
   ' calls toggle.. on the card. swaps a boolean.
   Call ToggleCheckInStatus(status)
   Call GetCardData(cardData)

   If cardData.TravelPassengerOnBoard = 1 Then
      Print "Checked in!"
   Else
      Print "Checked out!"
   End If
   
Else
   Print "You're not allowed to check-in or check-out!"
End If
   
